#include "StdAfx.h"
#include "OTL_Factory.h"

CDbFactory::CDbFactory(void)
{
}

CDbFactory::~CDbFactory(void)
{
}

otl_connect* CDbFactory::CreateDb( void )
{
	otl_connect* pdb=new otl_connect();
	otl_connect::otl_initialize(); 
	if (pdb)
	{
		pdb->rlogon("UID=admin;PWD=admin;DSN=WT_1011RC");
		return pdb;
	}
	return NULL;
}

void CDbFactory::ReleaseDb( otl_connect* ptr )
{
	if (ptr)
	{
		ptr->logoff();
		delete ptr;
		ptr=NULL;
	}
}

bool CDbFactory::Direct_exec( std::string& var_sql )
{
	otl_connect* db=CreateDb();

	try
	{
		otl_cursor::direct_exec(*db,var_sql.c_str()); 
	}
	catch(otl_exception& p)
	{
		ReleaseDb(db);
		return false;
	}
	
	ReleaseDb(db);
	return true;
}